#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'shawn'
__mtime__ = '2017/2/18'
# code is far away from bugs with the god animal protecting
    I love animals. They taste delicious.
              ┏┓      ┏┓
            ┏┛┻━━━┛┻┓
            ┃      ☃      ┃
            ┃  ┳┛  ┗┳  ┃
            ┃      ┻      ┃
            ┗━┓      ┏━┛
                ┃      ┗━━━┓
                ┃  神兽保佑    ┣┓
                ┃　永无BUG！   ┏┛
                ┗┓┓┏━┳┓┏┛
                  ┃┫┫  ┃┫┫
                  ┗┻┛  ┗┻┛
"""

import threading
import os
import sys
import sys
sys.path.append('/Users/shawn/oschina_workspaces/ScalersForum/src/S811_shawn')

from .scalers import storePost


def singleThreadFetch():
    threads = []

    rootdir = "scalersForumPost"

    ## 创建互斥锁
    mutex = threading.Lock()

    ##判断目录是否存在
    if not os.path.exists(rootdir):
        os.mkdir(rootdir)

    os.chdir(rootdir)

    #  从第一个帖子爬到到 484 个,没5个帖子一个线程。
    stepLength = 20
    #for i in range(2, 500, stepLength):
    i = 132
    storePost.fetchAndStoreForumPost(i, 1120, mutex, rootdir)

    print ("Finished!")


if __name__ == "__main__":
    # mutliThreadFetch()
    singleThreadFetch()

'''出现的问题:'''
'''/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 /Users/shawn/oschina_workspaces/ScalersForum/src/S811_shawn/mainFetch.py
Traceback (most recent call last):
  File "/Users/shawn/oschina_workspaces/ScalersForum/src/S811_shawn/mainFetch.py", line 27, in <module>
    from .scalers import storePost
SystemError: Parent module '' not loaded, cannot perform relative import'''